<template>
  <div class="risk">
    <div class="add" @click="add" v-if="editable">新增</div>
    <eagle-page-list
      :controller="controller"
      :queryParams="queryParams"
      @bindData="bindData"
      :conditions="conditions"
      ref="eaglePageList"
    >
      <template #list>
        <eagle-cell
          style="margin-top: 10px"
          class="br-8"
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="dep_item">
            <div class="dep_item_detail">
              <div @click="goDetail(item)">
                <div class="dep_name">{{ item.RiskUnitName || "无" }}</div>
                <div class="riskLevel" style="display: flex">
                  <div style="flex: 1">
                    固有风险:<span
                      class="riskLevelnone"
                      v-bind:class="{
                        riskLevel1: item.EvaluationValue == 'A/1级',
                        riskLevel2: item.EvaluationValue == 'B/2级',
                        riskLevel3: item.EvaluationValue == 'C/3级',
                        riskLevel5:
                          item.EvaluationValue == 'E/5级' ||
                          item.EvaluationValue == 'D/4级',
                      }"
                      >{{ getRiskLeveText(item.EvaluationValue) }}</span
                    >
                  </div>
                  <div style="flex: 1">
                    现状风险:<span
                      class="riskLevelnone"
                      v-bind:class="{
                        riskLevel1: item.EvaluationResultValue == 'A/1级',
                        riskLevel2: item.EvaluationResultValue == 'B/2级',
                        riskLevel3: item.EvaluationResultValue == 'C/3级',
                        riskLevel5:
                          item.EvaluationResultValue == 'E/5级' ||
                          item.EvaluationResultValue == 'D/4级',
                      }"
                      >{{ getRiskLeveText(item.EvaluationResultValue) }}</span
                    >
                  </div>
                </div>
                <div class="dep_sort">
                  <img src="@/assets/Images/AppIcon/icon_list_org.png" alt="" />
                  <div>所属区域：{{ item.OrgFullName || "无" }}</div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_danger.png"
                    alt=""
                  />
                  <div>
                    检查次数(年/月/日)：{{ item.YearTaskCount }}/{{
                      item.MonthTaskCount
                    }}/{{ item.DayTaskCount }}
                  </div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_danger.png"
                    alt=""
                  />
                  <div>
                    隐患数(年/月/日)：{{ item.YearHiddenCount }}/{{
                      item.MonthHiddenCount
                    }}/{{ item.DayHiddenCount }}
                  </div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                    alt=""
                  />
                  <div style="line-height: 16px">
                    整改率：{{
                      item.CorrectiveRate == -1
                        ? "无"
                        : item.CorrectiveRate + "%"
                    }}
                  </div>
                </div>
              </div>
              <eagle-divider />
              <div class="dep_btm" v-if="editable">
                <div class="btm_item" @click="goRiskLocation(item)">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-10">编辑</div>
                </div>
                <div class="btm_item" @click="del(item)">
                  <img src="@/assets/Images/AppIcon/icon_delete.png" alt="" />
                  <div>删除</div>
                </div>
              </div>
            </div>
          </div>
        </eagle-cell>
      </template>
    </eagle-page-list>
  </div>
</template>

<script>
import DeptmentChoose from "@/views/components/department/departmentChooseDialog.vue";

export default {
  components: {
    DeptmentChoose,
  },
  data() {
    return {
      editable: true,
      raCode: "",
      list: [],
      conditions: {},
      controller: "/RiskUnit",
      queryParams: {
          dataType: "ListNew",
      },
    };
  },
  created() {
    if (this.$route.query.raCode) {
      this.filter.dCode = this.$route.query.raCode;
      this.editable = false;
    }
    if (this.$route.query.orgCode) {
      this.filter.orgCode = this.$route.query.orgCode;
      this.editable = false;
    }
  },
  methods: {
    bindData(data) {
      this.list = [];
      if (data) {
        this.list = data;
      }
    },
    // 新增
    add() {
      this.$router.push("/Site_RiskUnit/RiskLocation?id=0");
    },
    // 编辑风险位置
    goRiskLocation(item) {
      this.$router.push("/Site_RiskUnit/RiskLocation?id=" + item.ID);
    },
    // 风险位置详情
    goDetail(item) {
      this.$router.push(
        "/Site_RiskUnit/RiskLocationDetail?code=" + item.RUCode
      );
    },
    del(item) {
      const id = item.ID;
      let _this = this;
      _this.$dialog
        .confirm({
          title: "询问",
          message: "您确定删除本条风险位置吗？",
        })
        .then(() => {
          _this.$axios
            .get("/RiskUnit/Delete", { params: { id } })
            .then((res) => {
              _this.$refs.eaglePageList.confirm();
            });
        });
    },
    getRiskLeveText(value) {
      var cls = "暂无";
      switch (value) {
        case "A/1级":
          cls = "重大风险";
          break;
        case "B/2级":
          cls = "较大风险";
          break;
        case "C/3级":
          cls = "一般风险";
          break;
        case "D/4级":
          cls = "低风险";
          break;
        case "E/5级":
          cls = "稍有危险";
          break;
        default:
          break;
      }
      return cls;
    },
  },
};
</script>
<style lang="less" scoped>
.van-divider {
  margin: 0;
}
</style>
<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  font-size: 14px;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.all_dep {
  background-color: #ffffff;
  padding: 10px;
  text-align: center;
}
.dep_item {
  width: 100%;
  background-color: #e8f1f8;
  color: #666;
}
.dep_item_detail {
  /* margin: 10px;*/
  padding: 10px;
  border-radius: 5px;
  background-color: #ffffff;
  position: relative;
  margin-bottom: 10px;
  padding-bottom: 0px;
  /* border-bottom: 1px solid #e8f1f8;*/
  .dep_name {
    font-size: 16px;
    color: #000;
  }
  .dep_sort {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
  .dep_btm {
    display: flex;
    justify-content: flex-end;
    line-height: 27px;
    .btm_item {
      display: flex;
      align-items: center;
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .riskLevel span {
    padding: 1px 8px;
    color: #fff;
    border-radius: 3px;
    font-size: 13px;
    margin-left: 8px;
  }
  .riskLevel {
    line-height: 35px;
    .riskLevelnone {
      background: green;
    }
    .riskLevel1 {
      background: #ff0000;
    }
    .riskLevel2 {
      background: #ffc000;
    }
    .riskLevel3 {
      background: #ffff00;
      color: #666;
    }
    .riskLevel5 {
      background: #00b0f0;
    }
  }
}
</style>
